package com.canaan.business.controller.pc.inOutStock;

import com.canaan.business.domain.inOutStock.StockOccupyDetail;
import com.canaan.business.domain.vo.StockOccupyDetailVo;
import com.canaan.business.service.inOutStock.IStockOccupyDetailService;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.core.page.TableDataInfo;
import com.canaan.common.enums.BusinessType;
import com.canaan.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库存占用明细Controller
 *
 * @author ruoyi
 * @date 2023-02-11
 */
@Api(tags = "库存占用明细")
@RestController
@RequestMapping("/occupy/detail")
public class StockOccupyDetailController extends BaseController {
    @Resource
    private IStockOccupyDetailService stockOccupyDetailService;

    /**
     * 查询库存占用明细列表
     */
    @ApiOperation(value = "查询库存占用明细列表")
    @GetMapping("/list")
    public TableDataInfo list(StockOccupyDetail stockOccupyDetail) {
        startPage();
        List<StockOccupyDetailVo> list = stockOccupyDetailService.selectStockOccupyDetailVoList(stockOccupyDetail);
        return getDataTable(list);
    }

    /**
     * 导出库存占用明细列表
     */
    @ApiOperation(value = "导出库存占用明细列表")
    @Log(title = "库存占用明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockOccupyDetail stockOccupyDetail) {
        List<StockOccupyDetail> list = stockOccupyDetailService.selectStockOccupyDetailList(stockOccupyDetail);
        ExcelUtil<StockOccupyDetail> util = new ExcelUtil<StockOccupyDetail>(StockOccupyDetail.class);
        util.exportExcel(response, list, "库存占用明细数据");
    }

    /**
     * 获取库存占用明细详细信息
     */
    @ApiOperation(value = "获取库存占用明细详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(stockOccupyDetailService.selectStockOccupyDetailById(id));
    }

    /**
     * 新增库存占用明细
     */
    @ApiOperation(value = "新增库存占用明细")
    @Log(title = "库存占用明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockOccupyDetail stockOccupyDetail) {
        return toAjax(stockOccupyDetailService.insertStockOccupyDetail(stockOccupyDetail));
    }

    /**
     * 修改库存占用明细
     */
    @ApiOperation(value = "修改库存占用明细")
    @Log(title = "库存占用明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockOccupyDetail stockOccupyDetail) {
        return toAjax(stockOccupyDetailService.updateStockOccupyDetail(stockOccupyDetail));
    }

    /**
     * 删除库存占用明细
     */
    @ApiOperation(value = "删除库存占用明细")
    @Log(title = "库存占用明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(stockOccupyDetailService.deleteStockOccupyDetailByIds(ids));
    }
}
